package com.biscuit.page.basicservice.model.enums;

import lombok.Getter;

import java.util.Arrays;

/**
 * @author mazihao
 * @createTime 2024/4/18 14:41
 */
@Getter
public enum VerificationCodeEnum {

    EMAIL_UPDATE_VERIFICATION_CODE(1, "邮箱修改验证码", "verification_code:update_new_email_check:number_", ""),
    EMAIL_LOGIN_VERIFICATION_CODE_LOGIN(2, "邮箱登录验证码", "verification_code:email_verification_code_login:number_", ""),
    MOBILE_UPDATE_VERIFICATION_CODE(3, "修改新手机验证码", "verification:code:update_new_mobile_check:number_", "");

    private final int type;
    private final String desc;
    private final String prefix;
    private final String bodyTemplate;

    VerificationCodeEnum(int type, String desc, String prefix, String bodyTemplate) {
        this.type = type;
        this.desc = desc;
        this.prefix = prefix;
        this.bodyTemplate = bodyTemplate;
    }

    public static VerificationCodeEnum getVerificationCodeTypeEnum(int type) {
        return Arrays.stream(VerificationCodeEnum.values())
                .filter(x -> x.type == type)
                .findFirst()
                .orElse(null);
    }

    public static String getVerificationCodeCacheKey(VerificationCodeEnum enumType, String body) {
        return enumType.getPrefix() + body + ":" + "code";
    }

    public static String getVerificationCodeCountCacheKey(VerificationCodeEnum enumType, String body) {
        return enumType.getPrefix() + body + ":" + "count";
    }

}
